//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    newUser: false,
    user: [],
    num: '',
    yhjnum: '',
    payPassword: '',
    // 组件所需的参数
    nvabarData: {
      showCapsule: 0, //是否显示左上角图标   1表示显示    0表示不显示
      title: '我的', //导航栏 中间的标题
    },
    // 此页面 页面内容距最顶部的距离
    height: app.globalData.height * 2 + 20,
  },
  loginUser() {
    wx.reLaunch({
      url: '/pages/login/login',
    })
  },
  onShow() {
    let url = app.globalData.URL + 'system/user/wx/info';
    console.log('url', url);
    let data = {};
    let that = this;
    app.wxRequest('GET', url, data, (res) => {
      console.log(res);
      if (res.code !== 200) {
        that.loginUser();
        return false;
      }
      let user = res.data.sysUser
      let payPassword = res.data.sysUser.payPassword;
      that.setData({
        user: user,
        payPassword: payPassword,
      })
      // that.mysb();
      // that.myyhj();
      // if(user.sysUser==null){
      //   wx.showModal({
      //     title: '请设置支付密码',
      //     success(){
      //       if (res.confirm) {
      //         wx.navigateTo({
      //           url: '/modelB/pages/my/setPassword/setPassword',
      //         })
      //       }else if (res.cancel) {
      //         console.log('用户点击取消')
      //       }


      //     }
      //   })
      // }
    }, (err) => {
      console.log(err.errMsg)
    })
  },
  myyhj() {
    let that = this;
    let url = app.globalData.URL + 'goods/coupon/user/list/0';
    let data = {};
    app.wxRequest('GET', url, data, (res) => {
      let coupon = res.rows
      let yhjnum = coupon.length;
      that.setData({
        yhjnum: yhjnum
      })
    }, (err) => {
    })
  },
  mysb() {
    let url = app.globalData.URL + 'facility/facility/wx/list';
    let data = {};
    app.wxRequest('GET', url, data, (res) => {
      if (res.rows) {
        let coupon = res.rows
        let num = coupon.length
        this.setData({
          num: num
        })
      }
    }, (err) => {
      console.log(err.errMsg)
    })
  },
  gobalance_details: function () {
    let money = this.data.user.money;
    wx.navigateTo({
      url: '/modelB/pages/my/balance_details/balance_details?money=' + money,
    })
  },
  gomy_device: function () {
    wx.navigateTo({
      url: '/modelB/pages/my/my_device/my_device',
    })
  },
  gomy_coupon: function () {
    wx.navigateTo({
      url: '/modelB/pages/my/my_coupon/my_coupon',
    })
  },
  modify_portrait: function () {
    wx.navigateTo({
      url: '/modelB/pages/my/my_info/my_info',
    })
  },
  goanty_records: function () {
    wx.navigateTo({
      url: '/modelB/pages/my/anty_records/anty_records',
    })
  },
  goquick_recharge: function () {
    let that = this;

    console.log(that.data.payPassword)
    if (that.data.payPassword == null) {
      wx.showModal({
        title: '请设置支付密码',
        success() {
          if (res.confirm) {
            wx.navigateTo({
              url: '/modelB/pages/my/setPassword/setPassword',
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    } else {
      wx.navigateTo({
        url: '/modelB/pages/my/quick_recharge/quick_recharge',
        success: function (res) { },
        fail: function (res) { },
        complete: function (res) { },
      })

    }
  },
  goprint_records: function () {
    wx.navigateTo({
      url: '/modelB/pages/my/print_records/print_records',
    })
  },
  gocommon_problem: function () {
    wx.navigateTo({
      url: '/modelB/pages/my/common_problem/common_problem',
    })
  },
  goline_service: function () {
    wx.navigateTo({
      url: '/modelB/pages/my/line_service/line_service',

    })
  },
  goaddress_manage: function () {
    wx.navigateTo({
      url: '/modelB/pages/my/address_manage/address_manage',

    })
  },
  goabout_us: function () {
    wx.navigateTo({
      url: '/modelB/pages/my/about_us/about_us',
    })
  }
})
